package org.jeecg.modules.flow.listener;

import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;

/**
 * 节点权限设置监听器
 */
//@Component("globalPermissionTaskListener")
@Slf4j
public class GlobalPermissionTaskListener implements TaskListener {


    @Override
    public void notify(DelegateTask delegateTask) {
       /* log.info("-----------环节权限注入监听器-------------");
        //List<ExtensionElement> list = delegateTask.getExecution().getCurrentFlowElement();
        //FlowElement currentFlowElement = delegateTask.getExecution().getCurrentFlowElement();
        //final String upper = FlowUtils.getExtAttributes(currentFlowElement, "upper");
        //log.info("------------------------" + upper);
        IFlowPermissionService flowPermissionService = SpringBeanUtils.getBean(FlowPermissionServiceImpl.class);
        // 监听任务创建事件
        if (delegateTask.getEventName().equals("create")) {
            String taskDefId = delegateTask.getTaskDefinitionKey();

            // TODO 需要判空
            Integer cusNo = delegateTask.getVariable("cusNo", Integer.class);
            String orgId = delegateTask.getVariable("orgId", String.class);
            // 获取任务权限配置信息
            TaskPermissionConfigDto dto = flowPermissionService.getTaskPermissionConfig(delegateTask.getProcessDefinitionId(), taskDefId, cusNo, orgId);
            String assignee = dto.getAssignee();
            // 如果候选人不为空则设置候选人
            if (StringUtils.isNotBlank(assignee)) {
                delegateTask.setAssignee(assignee);
            }
            // 设置候选用户
            delegateTask.addCandidateUsers(dto.getCandidateUsers());
            // 设置候选组
            delegateTask.addCandidateGroups(dto.getCandidateGroups());
        }
*/
    }
}
